import 'package:cached_network_image/cached_network_image.dart';
import 'package:chatgreat/helper/helper.dart';
import 'package:chatgreat/helper/my_widget.dart';
import 'package:chatgreat/page/component/image.dart';
import 'package:chatgreat/page/component/prompt_tags_selector.dart';
import 'package:chatgreat/page/component/theme/custom_theme.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_cache_manager/flutter_cache_manager.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';

class CreativeItem extends StatelessWidget {
  final String imageURL;
  final String iconImageURL;
  final String name;
  final String title;
  final Color? titleColor;
  final String? tag;
  final Function() onTap;
  final String size;
  const CreativeItem({
    super.key,
    required this.imageURL,
    required this.iconImageURL,
    required this.name,
    required this.title,
    required this.onTap,
    this.titleColor,
    this.tag,
    required this.size,
  });

  @override
  Widget build(BuildContext context) {
    final customColors = Theme.of(context).extension<CustomColors>()!;
    var memCacheWidth = ((ScreenUtil().screenWidth - 12 * 2 - 10) / 2).toInt();
    return InkWell(
      borderRadius: BorderRadius.circular(13),
      onTap: onTap,
      child: Stack(
        children: [
          SizedBox(
            width: double.infinity,
            height: double.infinity,
            child: ClipRRect(
              borderRadius: BorderRadius.circular(13),
              child: isNotBlank(imageURL)
                  ? CachedNetworkImage(
                      imageUrl: imageURL,
                      fit: BoxFit.cover,
                      width: (ScreenUtil().screenWidth - 12 * 2 - 10) / 2,
                      height: 100,
                      // memCacheWidth: memCacheWidth * 3,
                      // memCacheHeight: memCacheWidth * 2,
                      memCacheHeight: memCacheWidth ~/ 1.7 * 3,
                      // maxHeightDiskCache: 200,
                      // maxWidthDiskCache: 200,
                    )
                  : Image.asset('images/login_chat_icon.png',
                      fit: BoxFit.contain),
            ),
          ),
          if (size == 'large')
            Positioned(
              left: 20,
              top: 20,
              child: Row(
                children: [
                  Text(
                    title,
                    style: TextStyle(
                      color: titleColor ?? Colors.white,
                      fontSize: 30,
                    ),
                  ),
                  const SizedBox(width: 10),
                  if (tag != null && tag != '')
                    Tag(
                      name: tag!,
                      backgroundColor: customColors.linkColor,
                      fontsize: 10,
                    ),
                ],
              ),
            )
          else if (size == 'medium')
            Positioned(
              left: 20,
              top: 25,
              child: Row(
                children: [
                  Text(
                    title,
                    style: TextStyle(
                      color: titleColor ?? Colors.white,
                      fontSize: 20,
                    ),
                  ),
                  const SizedBox(width: 10),
                  if (tag != null && tag != '')
                    ScaleTransition(
                      scale: const AlwaysStoppedAnimation(0.5),
                      child: Tag(
                        name: tag!,
                        backgroundColor: customColors.linkColor,
                        fontsize: 10,
                      ),
                    ),
                ],
              ),
            )
          else
            Container(
              padding: const EdgeInsets.all(10),
              width: double.infinity,
              height: double.infinity,
              child: Column(
                crossAxisAlignment: CrossAxisAlignment.start,
                children: [
                  Row(
                    mainAxisAlignment: MainAxisAlignment.spaceBetween,
                    children: [
                      Expanded(
                          child: MyTextWeight(name, 15,
                              titleColor ?? Colors.white, FontWeight.w600)),
                      // 删除icon，不需要
                      // if (isNotBlank(iconImageURL))
                      //   SizedBox(
                      //     height: 12,
                      //     width: 12,
                      //     child: CachedNetworkImage(
                      //       width: 12,
                      //       height: 12,
                      //       memCacheWidth: 36,
                      //       memCacheHeight: 36,
                      //       imageUrl: iconImageURL,
                      //       fit: BoxFit.cover,
                      //     ),
                      //   )
                    ],
                  ),
                  const SizedBox(height: 2),
                  MyTextSingleScale(
                      title, 14, titleColor ?? Colors.white, FontWeight.w400)
                ],
              ),
            )
        ],
      ),
    );
  }
}
